home *** CD-ROM | disk | FTP | other *** search
/ NeXT Education Software Sampler 1992 Fall / NeXT Education Software Sampler 1992 Fall.iso / Programming / Source / tess / tess-1.0 / GeneratorOverlay.m-old < prev    next >
Encoding:
Text File  |  1992-06-30  |  3.4 KB  |  170 lines

  1. #import "GeneratorOverlay.h"
  2. #import "aGroup-inter.h"
  3. #import "Underlay.h"
  4. #define GENOFFT 20.0
  5. #define  BX  bounds.origin.x
  6. #define  BY  bounds.origin.y
  7. #define  BW  bounds.size.width
  8. #define  BH  bounds.size.height
  9. #define RESIZE 0
  10. #define ROTL 1
  11. #define ROTR 2
  12.  
  13.  
  14. @implementation GeneratorOverlay
  15. + new
  16. {
  17.   self = [super new];
  18.   bframe.origin.x = bframe.origin.y = 0.0;
  19.   bframe.size.width = bframe.size.height = 32.0;
  20.   lbut = [[[Button new]
  21.       initFrame: &bframe icon: "rotatel" tag: ROTL target: self 
  22.       action: @selector(rotate:) key: 0 enabled: YES]
  23.       setContinuous: YES];
  24.   bframe.origin.x = 32.0;
  25.   rbut = [[[Button new]
  26.       initFrame: &bframe icon: "rotater" tag: ROTR target: self 
  27.       action: @selector(rotate:) key: 0 enabled: YES]       
  28.         setContinuous: YES];
  29.   bframe.origin.x = 64.0;
  30.   rebut = [[[[Button new]
  31.       initFrame: &bframe icon: "resize" tag: RESIZE target: self 
  32.       action: @selector(resizeAction:) key: 0 enabled: YES]
  33.         setAutodisplay: NO]
  34.        setNeedsDisplay: YES];
  35.   return self;
  36. }
  37.  
  38. - setupGenerator: (id) agroup
  39. {
  40.   NXSize si;
  41.   resizing = NO;
  42.   group = agroup;
  43.   [group getGeneratorSize: &si];
  44.   [self moveTo: 0.0 : 0.0 ];
  45.   [self sizeTo: si.width + 2.0* GENOFFT : si.height + 2.0 * GENOFFT ];
  46.   [self placeResizer];
  47.   return self;
  48. }
  49.  
  50. - erase
  51. {
  52.   scratch = [under getImage];
  53.   [scratch composite: NX_COPY fromRect: &frame toPoint: &(bounds.origin)];
  54.   return self;
  55. }
  56.  
  57. - drawSelf:(const NXRect *)rects :(int)rectCount
  58. {
  59.   scratch = [under getImage];
  60.   // draw transparent rect filling view
  61.   PSgsave();
  62.   PSsetrgbcolor(0.0,1.0,1.0);
  63.   PSsetalpha(0.5);
  64.   PScompositerect(BX,BY,BW,BH,NX_SOVER);
  65.   PSgrestore();
  66.   PSsetgray(1.0);
  67.   PSrectfill(BX+BW-GENOFFT,BY+BH-GENOFFT,GENOFFT,GENOFFT); // hotspot for resize
  68.   // composite generator back to view base + (5,5)
  69.   [group clip:GENOFFT:GENOFFT];
  70.   [scratch composite: NX_COPY fromRect: &frame toPoint: &(bounds.origin)];
  71.   [rebut display];
  72.   return self;
  73. }
  74.  
  75. - setUnderlay: (id) pad
  76. {
  77.   under = pad;
  78.   return self;
  79. }
  80.  
  81. - getGeneratorOffset: (NXPoint *) pt
  82. {
  83.   pt->x = frame.origin.x + GENOFFT;
  84.   pt->y = frame.origin.y + GENOFFT;
  85.   return self;
  86. }
  87.  
  88. - mouseDownAction:(NXPoint *)pt
  89. {
  90.   dx = pt->x;
  91.   dy = pt->y; 
  92.   return self;
  93. }
  94.  
  95. - mouseUpAction:(NXPoint *)pt
  96. {
  97.   resizing=NO;
  98.   return self;
  99. }
  100.  
  101. - mouseDraggedAction:(NXPoint *)pt
  102. //move view under mouse
  103. {
  104.     [self convertPointToSuperview: pt];
  105.     if([self lockFocus])
  106.       [self erase];
  107.     else {
  108.       [self erase];
  109.       [self unlockFocus];
  110.     }
  111.     if(resizing)
  112.       [self resize: pt];
  113.     else {
  114.       pt->x -= dx;
  115.       pt->y -= dy;
  116.       [self moveTo: pt->x : pt->y];
  117.     }
  118.     [self display];
  119.     return self;
  120. }
  121.  
  122. - resize: (NXPoint *) pt
  123. {
  124.   float xsc,ysc,x,y;
  125.  
  126.   [self convertPointFromSuperview: pt];
  127.   if(pt->x <= GENOFFT) {
  128.     x = BW; xsc = 1.0;
  129.   } else {
  130.     x = pt->x; xsc = pt->x / BW;
  131.   }
  132.   if(pt->y <= GENOFFT){
  133.     y = BH; ysc = 1.0;
  134.   } else {
  135.     y = pt->y; ysc = pt->y / BH;
  136.   }
  137.   fprintf(stderr,"New scaling: %f %f\n",xsc,ysc);
  138.   [group setScaling: xsc : ysc];
  139.   [self sizeTo: pt->x : pt->y];
  140.   [self placeResizer];
  141.   return self;
  142. }
  143.  
  144. - resizeAction: sender
  145. {
  146.   resizing = YES;
  147.   fprintf(stderr,"Resize button clicked. Sending next event\n");
  148.   [self becomeFirstResponder];
  149.   [self mouseDown: [NXApp currentEvent]];
  150.   return self;
  151. }
  152.  
  153. - placeResizer 
  154. {
  155.   float x,y;
  156.   NXRect fr;
  157.  
  158.   [rebut getFrame: &fr];
  159.   x = fr.size.width;
  160.   y = fr.size.height;
  161.   [rebut moveTo: BW - x : BH - y];
  162.   return self;
  163. }
  164.  
  165. - rotate: sender 
  166. {
  167.   return self;
  168. }
  169. @end
  170.